<template>
    <div>
        <h1>权益显示</h1>
    </div>
    <table class="table">
        <tbody>
            <tr>
                <td>权益Id</td>
                <td>权益名称</td>
                <td>状态</td>
                <td>操作</td>
            </tr>
            <tr v-for="item in info" :key="item.userNoeId">
                <td>{{ item.userNoeId }}</td>
                <td>{{ item.userNoeName }}</td>
                <td>{{ item.state == 1 ? "开启" : "禁用" }}</td>
                <td>
                    <input type="button" value="删除" class="btn btn-danger" @click="del(item.userNoeId)">

                    <input type="button" value="修改状态" class="btn btn-info" @click="a(item.userNoeId)">

                    <input type="button" value="修改" class="btn btn-success" @click="updatee(item.userNoeId)">
                </td>
            </tr>
        </tbody>
    </table>
</template>

<script setup lang="ts">

import { ref, reactive, onMounted } from 'vue'
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';
const route = useRoute();
const router = useRouter();

let info: any = reactive({

})
onMounted(() => {
    show();
})

const show = () => {
    axios({
        url: 'https://localhost:7173/api/User/GetUserNoe',
        method: 'get',
        params: info,
    })
        .then(res => {
            Object.assign(info, res.data);
        })
}
const updatee = (id: any) => {
    let f = confirm("确认要修改吗");
    if (f) {
        router.push({
            path: '/updateUserNoe',
            query: { id: id }
        })
    }

}


const del = (id: any) => {
    let f = confirm("确认删除吗");
    if (f) {
        axios({
            url: 'https://localhost:7173/api/User/DelUserNoe',
            method: 'delete',
            params: {
                ids: id,
            }
        })
            .then(res => {
                if (res.data > 0) {
                    alert("删除成功");
                    show();
                    return;
                }
                else {
                    alert("删除失败");
                    return;
                }
            })
    }
}

const a = (id: any) => {
    axios({
        url: 'https://localhost:7173/api/User/UpdateUserNoe',
        method: 'put',
        params: {
            ids: id,
        }
    })
        .then(res => {
            if (res.data > 0) {
                show();
                return;
            }
        })
}
</script>

<style scoped></style>